package com.example.activity_service.controller;

import com.example.activity_service.service.MsQueryService;
import com.example.activity_service.vo.StopWatch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Random;

@RestController
@ResponseBody
public class MsController {

    @Autowired
    MsQueryService service;

    @RequestMapping("/login")
    public String diaoyong(){
        return "looklook" ;
    }

    //    获取全部时间5个
    @RequestMapping("/huoqusj")
    public List<StopWatch> huoqusj(){
        List<StopWatch> list=service.huoqusj();
        return list;
    }
    //    获取一个时间
    @RequestMapping("/huoqusj1")
    public List<StopWatch> huoqusj1(){
        List<StopWatch> list=service.huoqusj1();
        return list;
    }
    int commodityid = new Random().nextInt(10000);

    //添加时间
    @RequestMapping("/tjsj")
    public int tjsj(@RequestParam("openingtime")String openingtime,
                    @RequestParam("endtime")String endtime,
                    StopWatch stopWatch){
//        System.out.println(openingtime);
//        System.out.println(endtime);

        stopWatch.setCommodityid(commodityid++);
        int sj=service.tjsj(stopWatch);
        return sj;
    }
    //    修改时间状态
    @RequestMapping("/gai")
    public int gai(@RequestParam("endtime")String endtime,
                   StopWatch stopWatch){
//        System.out.println(endtime);
        int sj=service.gai(stopWatch);
        return sj;
    }

    //    根据商品关联id查询切换图片
    @RequestMapping("/qiehuan")
    public List<StopWatch> qiehuan(@RequestParam("commodityid")String commodityid,
                                   @RequestParam("msid")String msid,
                                   StopWatch stopWatch){
//        System.out.println(commodityid);
        System.out.println(msid+"时间编号");
//         int e=service.shuliang0();
        List<StopWatch> sj=service.qiehuan(stopWatch);
        return sj;
    }
    //    查msid
    @RequestMapping("/selectmsid")
    public List<StopWatch> selectmsid(@RequestParam("msid")int msid,
                                      StopWatch stopWatch){
//        System.out.println(msid);
        List<StopWatch> sj=service.selectmsid(stopWatch);
        return sj;
    }

    //    修改时间状态
    @RequestMapping("/jianyi")
    public int jianyi(@RequestParam("goodsid")int goodsid){
        int sj=service.jianyi(goodsid);
        return sj;
    }
    //数量变成0 中间表
//    @RequestMapping("/shuliang0")
//    public int shuliang0(@RequestParam("goodsid")int goodsid,
//                         StopWatch stopWatch){
//        int e=service.shuliang0(goodsid);
//        return e;
//    }


    //    获取全部商品
    @RequestMapping("/chagoods")
    public List<StopWatch> chagoods(){
        List<StopWatch> list=service.chagoods();
        return list;
    }

    //添加商品时间
    @RequestMapping("/shangpintianjia")
    public int shangpintianjia(@RequestParam("openingtime")String openingtime,
                               @RequestParam("spikeprice")String spikeprice,
                               @RequestParam("goodsid")String goodsid,
                               StopWatch stopWatch) {
//        System.out.println(openingtime);
//        System.out.println(goodsid);
//        System.out.println(spikeprice);
        int sj = service.shangpintianjia(openingtime, spikeprice, goodsid);
        return sj;
    }
    @RequestMapping("/shouye")
    public List<StopWatch> shouye(@RequestParam("commodityid")String commodityid,
                                  @RequestParam("msid")String msid,
                                  StopWatch stopWatch) {
        List<StopWatch> list = service.shouye(stopWatch);
        return list;
    }
}
